/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.fiap.server;

import JPA.Satisfacao;
import java.io.IOException;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author rm65556
 */
@WebServlet(urlPatterns="/ProcessarSatisfacao")
public class ProcessarSatisfacao extends HttpServlet{
    
    private EntityManagerFactory fabricaEntityManager;
    public void init()throws ServletException{
        fabricaEntityManager = Persistence.createEntityManagerFactory("sistemaWeb");
    }
    
    @Override
    protected void doPost (HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException{
       
        Satisfacao satisfacao = new Satisfacao();
        satisfacao.setNome(req.getParameter("nome"));
        satisfacao.setSexo("sexo");
        satisfacao.setGrau("satisfacao");
        satisfacao.setProduto("produto");
        satisfacao.setComentario("comentario");
        satisfacao.setAutorizaContato("contatar"); 
               
        
        EntityManager motor = fabricaEntityManager.createEntityManager();
        motor.getTransaction().begin();
        motor.persist(satisfacao);
        motor.getTransaction().commit();
        
    }
    
}
